﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ContadorDeHoras.DTO;
using System.Data.SqlClient;

namespace ContadorDeHoras.DAL
{
    public class CommandRetrieveByMonth:ICommand
    {
        private DiaDTO dia;
        public CommandRetrieveByMonth(DiaDTO dia)
        {
            this.dia = dia;
        }
        public object execute()
        {
            List<DiaDTO> retorno = new List<DiaDTO>();
            Connection conexao = Connection.getConnection();
            SqlCommand c = new SqlCommand("s_sp_by_month", conexao.getConexao());
            c.CommandType = System.Data.CommandType.StoredProcedure;
            c.Parameters.Add(new SqlParameter("@month", this.dia.Dia.Month));
            c.Parameters.Add(new SqlParameter("@year", this.dia.Dia.Year));
            SqlDataReader dr = c.ExecuteReader();
            while (dr.Read())
            {
                retorno.Add(new DiaDTO(dr.GetDateTime(0),dr.GetDateTime(1),dr.GetDateTime(2),dr.GetDateTime(3),dr.GetDateTime(4)));
            }
            conexao.closeConexao();
            return retorno;
        }
    }
}
